
const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu('common/GCToast')
export default class GCToast extends cc.Component {

    @property(cc.Label)
    toastLbl: cc.Label = null;

    protected onLoad(): void {
        cc.game.addPersistRootNode(this.node);
        this.node.active = false;
    }

    public static toast(msg: string) {
        const node = cc.find('Toast');
        if (!node) {
            cc.error('Not Found Toast');
            return;
        }

        const comp = node.getComponent(GCToast);
        comp.toastLbl.string = msg;
        node.active = true;
        node.y = 720;

        cc.tween(node)
            .delay(1.5)
            .by(0.2, { y: 150, opacity: 0 }, { easing: 'sineOut' })
            .call(() => {
                node.active = false;
            })
            .start();
    }
}

if (CC_DEBUG) {
    (window as any).GCToast = GCToast;
}
